Skip to content

feat(service-knowledge): search inside chosen records — the record scope, by the records a source indexes or by a parent through a listed lookup - #37342

Merged
objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/project-thread-3zr6fx
Nov 26, 2026
Merged

objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/project-thread-3zr6fx

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #37308

Clause-②: yes
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:知识检索可以限定范围了:只在指定的几条记录里找,或者只在一份上级记录(比如一份制度)下面的条款里找,返回的前几条结果都来自范围内。
  • 为什么做:属于「知识检索平台化」专题第三阶段,按您定的「也能指定上级对象(制度)」实现;之后给 AI 用的检索工具也会接上这个参数。
  • 出错会怎样:范围只会缩小结果,不会放宽权限,每条结果仍按提问人的权限重新读取;最坏是限定范围后漏掉结果。没有数据迁移,撤回即可。
  • 要你做什么:无需你操作。您已在卡片上同意的安全登记行已在(d1ca7f01)。开源向量库那个改动先合并了,本分支已合入主干,并让向量库也按范围过滤(在数据库里先筛再排序);由座位做差量复核后重新排队合并。「按记录返回」已合并并合入本分支;与开源向量库那个改动仍有文字冲突,后合并的一方处理。

What changes

ADR-0161 K8 item 17, in the shape its dated note of 2026-11-25 (#37324, merged as 13ffe1c0) gives it, built in one PR as the note says: the member, its first reader in knowledge-memory, and the suite cases.

@objectstack/spec (types only, no metadata key):

  • KnowledgeSearchOptions.scope?: Array<{ object: string; ids: string[] }> (packages/spec/src/contracts/knowledge-service.ts): an option of the service, not a contract member. Its TSDoc states the own-object and parent readings, union, absent/empty, and the bounds with the coded refusal.
  • AdapterSearchOptions.scope?: AdapterScopeTerm[] and the exported type AdapterScopeTerm (packages/spec/src/contracts/knowledge-adapter.ts): { kind: 'record', ids } or { kind: 'metadata', field, ids }. Its TSDoc states absent/present/empty, the AND with organizationIds and filter, the bounds an adapter can rely on (at most 10 terms, at most 500 ids each, every id a non-empty string), and that the service checks every hit after the answer, so an adapter returns the document's metadata on its hits.
  • Regenerated: api-surface/contracts.json, export-origins/contracts.json (the new export).

@objectstack/service-knowledge:

  • New src/knowledge-search-scope.ts:
    • readSearchScope: the bounds, SEARCH_SCOPE_MAX_ENTRIES = 10, SEARCH_SCOPE_MAX_IDS = 500. Past them it throws code: 'VALIDATION_ERROR', status: 400 (ADR-0112), naming the bound, before anything else in search runs.
    • scopeTermsFor: an entry naming the source's object gives a record term. An entry naming another object gives a metadata term on the one metadataFields member that is a lookup or master_detail field whose referenceTargetOf is that object, read from the registered definition. A user field, a withheld (credential-class or internal) field, a field whose target cannot be read, two or more such fields, no definition, and a file / http source all give nothing.
    • scopeCheck: the hit check. It judges sourceRecordId or metadata[field], compares strings and numbers by String(v), and matches a list when any element matches. Anything else, or no value, fails closed.
  • KnowledgeService.search:
    • Validates first.
    • sourcesInScope pairs each admitted source with its terms. A source no entry reaches is not searched (debug). The two-lookup ambiguity is logged once per source and object at warn, naming the fields.
    • searchRound hands each adapter a copy of its terms and checks every hit after the answer. The first drop for an adapter is logged once at warn.
    • answered stays the adapter's own count.
  • src/testing.ts (the contract suite):
    • New required implements.scope.
    • Adapter-alone cases, run when implements.scope is true: a record term filters before ranking (topK 1); a metadata term with a list value returns the document's metadata; the number 7 matches '7'; terms are a union; an empty list or a term with no ids ranks nothing; without the member everything is ranked; with organizationIds, both apply.
    • Cases through a real KnowledgeService for every adapter: an own-object scope fills topK from in-scope passages; a parent scope works through the listed lookup; an adapter with the member stripped answers no out-of-scope hit, and the service logs once.
    • serviceOver gains schemas, stripScope and logger.

@objectstack/knowledge-memory: applies scope after the organization filter and before scoring. It declares implements.scope: true.

@objectstack/knowledge-pgvector (landed first, #37337): applies scope in the same inner WHERE as the organization filter, before ORDER BY / LIMIT. A record term is source_record_id = ANY($n::text[]); a metadata term holds when the stored jsonb value of its field is a string or number equal to an id as text, or a list with such an element. Ids and field names are bound parameters only. A scope with no term that has ids answers [] before any query. Its live contract run declares implements.scope: true.

Docs:

  • content/docs/protocol/knowledge.mdx: a new "Record scope" section in §5, a pointer in §3.4, the suite sample, and §4.1 / the adapter table naming pgvector's record scope.
  • content/docs/ai/knowledge-rag.mdx: a new "Searching inside chosen records" section.

Changeset: patch for the four packages, with Clause-②: yes and Metadata-protocol: none. The change adds no metadata key, and a non-protocol widening ships patch.

Tests

  • New src/__tests__/knowledge-search-scope.test.ts: bounds (each refusal, and the exact-bound acceptance), term building (each reading of the note), and the hit check.
  • src/__tests__/knowledge-service.test.ts, new describe "search scope (ADR-0161 K8, item 17)":
    • the card's acceptance: 20 records, two in scope, topK 5, a full page;
    • an ignoring adapter: no out-of-scope hit, one log;
    • an unreached object: no adapter asked, empty answer;
    • an unreadable scoped record yields no hit;
    • the bounds refuse before any adapter or engine call;
    • empty scope and empty ids answer nothing;
    • the two-lookup case logs once;
    • a numeric lookup value matches its string id;
    • a parent scope makes no engine call naming the parent object, and an adapter that widens the terms it was handed (more ids, an extra term) still has every out-of-scope hit dropped; every round is handed the service's own terms (review round 1);
    • a scope with groupBy, and one with granularity: 'record', over an adapter that ignores the scope: every round is handed the record term and no out-of-scope record answers (review round 2).
  • The contract suite runs on knowledge-memory and both stubs.
  • Mutation checks, run locally and reverted:
    • knowledge-memory with its scope filter removed: 7 suite cases fail.
    • KnowledgeService without the after-answer check: 7 cases fail across the stubs and the service tests.
    • Handing the adapter the live terms, or reading the parent object's definition: the round-1 case fails.
    • Skipping the scope under groupBy, skipping it under record granularity, or the groupBy source filter rebuilding its entries without the terms: the round-2 case fails.

Local runs at 760716bc (after merging main at 98bda0ac, which brought #37337):

  • pnpm --filter @objectstack/spec build and check:generated: exit 0, after the merge's deferred regeneration of api-surface/contracts.json and export-origins/contracts.json (4552e7c4).
  • pnpm --filter @objectstack/service-knowledge typecheck and check:test-typecheck: exit 0. test: 13 files, 365 tests passed.
  • pnpm --filter @objectstack/knowledge-memory typecheck and check:test-typecheck: exit 0. test: 2 files, 56 tests passed.
  • pnpm --filter @objectstack/knowledge-pgvector typecheck: exit 0. test against a local PostgreSQL 16 with pgvector, OS_TEST_POSTGRES_URL set and OS_EXPECT_LIVE_DIALECT_MATRIX=1: 4 files, 67 tests passed, every scope case of the suite among them (record term, metadata term with a list, the number 7, union, empty, absent, with organizationIds; through the service: own object, the parent through the listed lookup, the member stripped). With the SQL scope filter removed: 7 of them fail.
  • pnpm --filter @objectstack/core test:repo (the census pin, at d1ca7f01): 8 files, 110 tests passed.
  • Derived gates at 760716bc. dispatch-gates --commands derives 119 commands from the 19 changed paths (the 118 before, plus pnpm check:kernel-hook-pairs). Each was run at this head with its output in its own file and its exit code read before any pipe. check:dual-build-cjs-loads first answered 3 (prerequisite not met: the new knowledge-pgvector had no dist/); after pnpm --filter @objectstack/knowledge-pgvector build it was run again, and the record holds that run.
Run reconciliation — 119 derived, 119 run, 0 NOT-MEASURED, 0 UNRUN.
✓ dispatch-gates --ran: 119 derived famil(ies) accounted for — 119 run, 0 NOT-MEASURED (a DERIVED zero — all 119 recorded an exit code and none of them is 3).
The 119 commands at 760716bc
Command Exit
node scripts/check-adr-0087-registration.mjs --base origin/main 0
node scripts/check-adr-0087-registration.mjs --self-test 0
node scripts/check-adr-links.mjs 0
node scripts/check-adr-links.mjs --self-test 0
node scripts/check-changeset-no-major.mjs --base origin/main 0
node scripts/check-closing-keyword-parity.mjs 0
node scripts/check-closing-keyword-parity.mjs --self-test 0
node scripts/check-comment-mask-adoption.mjs 0
node scripts/check-comment-mask-adoption.mjs --self-test 0
node scripts/check-comment-mask-corpus.mjs 0
node scripts/check-dev-prereqs.mjs --self-test 0
node scripts/check-doc-route-spelling.mjs --advisory 0
node scripts/check-doc-route-spelling.mjs --self-test 0
node scripts/check-docs-section-name.mjs 0
node scripts/check-docs-section-name.mjs --self-test 0
node scripts/check-dts-emitted.mjs --self-test 0
node scripts/check-empty-changeset.mjs --base origin/main 0
node scripts/check-empty-changeset.mjs --self-test 0
node scripts/check-issue-citations.mjs 0
node scripts/check-plugin-teardown-shape.mjs 0
node scripts/check-plugin-teardown-shape.mjs --self-test 0
node scripts/check-section-landing-index.mjs 0
node scripts/check-section-landing-index.mjs --self-test 0
node scripts/check-tenant-audit-census.mjs 0
node scripts/check-tenant-audit-census.mjs --self-test 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test 0
node scripts/ci/plan-test-core-shards.mjs --self-test 0
node scripts/ci/prune-turbo-cache.mjs --self-test 0
node scripts/ci/snapshot-next.mjs --self-test 0
node scripts/docs-audit/check-affected-docs.mjs 0
node scripts/docs-audit/check-drift-comment.mjs 0
node scripts/pm/check-governed-queue-guard.mjs --self-test 0
node scripts/pm/release-rehearsal-clone.mjs --self-test 0
node scripts/release-pending-publish.mjs --self-test 0
pnpm --filter @objectstack/lint run check:doc-formula-expressions 0
pnpm --filter @objectstack/lint run check:doc-security-posture 0
pnpm --filter @objectstack/spec run check:api-surface 0
pnpm --filter @objectstack/spec run check:authorable-surface 0
pnpm --filter @objectstack/spec run check:browser-reachable-entries 0
pnpm --filter @objectstack/spec run check:docs 0
pnpm --filter @objectstack/spec run check:dual-source-exports 0
pnpm --filter @objectstack/spec run check:duration-unit-keys 0
pnpm --filter @objectstack/spec run check:empty-state 0
pnpm --filter @objectstack/spec run check:entry-nameability 0
pnpm --filter @objectstack/spec run check:error-code-provenance 0
pnpm --filter @objectstack/spec run check:export-origins 0
pnpm --filter @objectstack/spec run check:exported-any 0
pnpm --filter @objectstack/spec run check:generated 0
pnpm --filter @objectstack/spec run check:liveness 0
pnpm --filter @objectstack/spec run check:llms-txt 0
pnpm --filter @objectstack/spec run check:skill-examples 0
pnpm --filter @objectstack/spec run check:skill-refs 0
pnpm --filter @objectstack/spec run check:strictness-ledger 0
pnpm --filter @objectstack/spec run check:variant-docs 0
pnpm --filter @objectstack/spec run check:yaml-examples 0
pnpm check:adr-anchors 0
pnpm check:adr-symbol-anchors 0
pnpm check:changeset-gate-self-tests 0
pnpm check:ci-filter-parity 0
pnpm check:closed-ceremony-text 0
pnpm check:corpus-claim-drift 0
pnpm check:cross-package-test-inputs 0
pnpm check:dispatcher-error-vocabulary 0
pnpm check:doc-anchors 0
pnpm check:doc-authoring 0
pnpm check:doc-frontmatter 0
pnpm check:docs-audit-scope 0
pnpm check:docs-redirects 0
pnpm check:docs-single-h1 0
pnpm check:docs-spec-enumerations 0
pnpm check:docs-transcript-drift 0
pnpm check:driver-memory-census 0
pnpm check:dts-closure 0
pnpm check:engine-double-contract 0
pnpm check:error-status-conformance 0
pnpm check:gitlink-declared 0
pnpm check:init-service-contract 0
pnpm check:issue-citations 0
pnpm check:kernel-hook-pairs 0
pnpm check:keyed-text-bounds 0
pnpm check:lean-entry-closure 0
pnpm check:logger-receiver-detach 0
pnpm check:merge-driver 0
pnpm check:nul-bytes 0
pnpm check:object-def-param-keys 0
pnpm check:objectql-double-limit 0
pnpm check:optional-error-sink 0
pnpm check:org-identifier 0
pnpm check:package-naming 0
pnpm check:page-declaration-shape 0
pnpm check:platform-object-tenancy-census 0
pnpm check:pm-expected-skips 0
pnpm check:pm-prior-rulings 0
pnpm check:published-files 0
pnpm check:published-readme-links 0
pnpm check:query-options-erasure 0
pnpm check:react-page-adapter-contract 0
pnpm check:refd-timer-probe 0
pnpm check:registry-log-declared 0
pnpm check:rest-log-spy-declared 0
pnpm check:role-word 0
pnpm check:settings-bind-window 0
pnpm check:skill-identifier-liveness 0
pnpm check:slot-lookup 0
pnpm check:sourcemap-no-sources-content 0
pnpm check:spec-docblock-symbol-anchors 0
pnpm check:spec-parsed-alias 0
pnpm check:startup-registry-verdict 0
pnpm check:system-context-census 0
pnpm check:test-source-alias 0
pnpm check:tier-file-adoption 0
pnpm check:type-check-coverage 0
pnpm check:type-check-debt 0
pnpm check:undeclared-dep-imports 0
pnpm check:vendor-version-stamps 0
pnpm check:vouch-for-reference-callers 0
pnpm check:watch-hint-literal 0
pnpm check:where-matcher 0
pnpm check:dual-build-cjs-loads 0

Earlier heads ran the 118 then derived, all exit 0: 857a2e20 (after three prerequisites were met) and ca5a0c11.

Acceptance notes

The five points carried from #37329's contract review:

  1. Metadata on hits. The requirement that an adapter return the document's metadata is stated on AdapterSearchOptions.scope and on KnowledgeHit.metadata (packages/spec/src/ai/knowledge-document.zod.ts, added in the merge of main under the seat's claim amendment, review ruling (b)). It is pinned: the suite's metadata-term case and the parent case through the service both assert hit.metadata.policy.
  2. Ids compared as strings. Pinned on scopeCheck, on the adapter in the suite, and through the service (a lookup stored as the number 7 matches '7'). Only strings and numbers compare. An object, null or a boolean never matches, so '[object Object]' cannot be matched by accident.
  3. An empty scope or an entry with no ids. It is answered empty, never refused and never read as "no scope", and no adapter is asked. Why empty rather than refused: it reads as an empty set reads everywhere else in this contract (organizationIds: []). A caller that computes ids (the records on screen, a policy's children) then needs no special case for "none". The tool argument (search_knowledge: the one definition gains scope, granularity and groupBy, for the MCP door and the in-app agent alike #37311) can still refuse at its own door.
  4. Bounds. 10 entries and 500 ids per entry are stated on both TSDocs and pinned. The 500 ids of one term fit one IN list, and a search hands at most 5,000 ids in all. ⚑ This PR owes a ceiling-tier contract review (CONTRACT_REVIEW_TIER) for the new member.
  5. The opaque filter. Finding for the seat to file: KnowledgeSearchOptions.filter / AdapterSearchOptions.filter has no producer in this tree. The one non-test caller of IKnowledgeService.search, createKnowledgeTools, passes none, and the service gives it no guarantee after the answer. This PR leaves it unchanged and builds nothing from it. Whether it retires is its own card. Carrier: none · noted, not filed. Dedupe words: knowledge opaque filter, AdapterSearchOptions filter retire, KnowledgeSearchOptions filter producer.

What the note left to this PR, decided here:

  • Refill. answered stays the adapter's own count, so whether a source may hold more is still judged on what it returned. The refill after the permission filter counts records among the hits that passed both checks.
    • A person's search over an ignoring adapter therefore still reaches in-scope hits through the refill.
    • The system identity gets one round, and may answer fewer than topK (pinned).
  • Log levels.
    • An adapter whose hits the check drops: warn, once per adapter. It is a deployment defect, and rule 2 says nothing is skipped silently.
    • Two lookups to one parent: warn, once per source and object. It is an authoring defect.
    • A source a scope does not reach: debug, per search, because it is normal under a scope.
    • Counts appear in logs only, never in the answer.
  • Entry shape. An entry with another key (for example field) is refused rather than ignored. A field key is the note's deferred alternative, so it fails loud instead of silently reading as something else. An id that is not a non-empty string is refused: the contract types ids as strings, and a stored numeric value still matches its string id.

Surface and overlap:

Verification

Read first:

  1. packages/services/service-knowledge/src/knowledge-search-scope.ts: the whole module (bounds, term building, hit check).
  2. KnowledgeService.search / sourcesInScope / searchRound / checkScope in knowledge-service.ts: the three-line change at the top of search, and the check after the answer.
  3. The two TSDocs in packages/spec/src/contracts/.

Two-minute check: run pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-search-scope.test.ts src/__tests__/knowledge-service.test.ts -t scope. Then open the "search scope" describe and read the acceptance case "20 records, two of them in scope, topK 5".


Generated by Claude Code

…nds its adapter (#37324)

A second dated note under the table of K8, and a second Amended bullet in
the header list. The note records the maintainer's ruling on Q3 (ruling
record 7168192820) and gives item 17 its final shape: the member is
AdapterSearchOptions.scope, a list of terms the service builds from
scope: [{ object, ids }] and the adapter applies before it ranks. No
code, no schema, no changeset. The status line is left as it is.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
…ords, or to the records under one parent

ADR-0161 K8 item 17, as its dated note of 2026-11-25 shapes it.

- spec: KnowledgeSearchOptions.scope [{ object, ids }] with its bounds;
  AdapterSearchOptions.scope and the AdapterScopeTerm type (record /
  metadata terms), the bounds and the service's check stated on the member.
- service-knowledge: knowledge-search-scope.ts holds a scope to its bounds
  (VALIDATION_ERROR 400 before any adapter is called), builds each source's
  terms (own object -> record term; a parent -> the one listed lookup or
  master_detail field pointing at it, read through referenceTargetOf; user
  fields, withheld fields and two-or-more links reach nothing), and checks
  every hit after the adapter answers, fail closed, logging once per adapter.
  A source no entry reaches is not searched; an empty scope answers nothing.
- knowledge-memory: applies the scope before ranking (first reader).
- testing.ts: implements.scope; per-term-kind adapter cases and cases through
  a real KnowledgeService, one over the adapter with the member stripped.
- docs: protocol "Record scope" section; RAG guide section.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 4 package(s): @objectstack/knowledge-memory, @objectstack/knowledge-pgvector, @objectstack/service-knowledge, @objectstack/spec, touching 42 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/ai/knowledge-rag.mdx (via KnowledgeService (symbol, a top-level class))
  • content/docs/permissions/system-context.mdx (via searchWithRefusals (symbol, a method of class KnowledgeService))
  • content/docs/protocol/knowledge.mdx (via AdapterSearchOptions (symbol, a top-level interface), KnowledgeHitSchema (symbol, a top-level const), KnowledgeSearchOptions (symbol, a top-level interface), KnowledgeService (symbol, a top-level class), runKnowledgeAdapterContract (symbol, a top-level function))
What this run could not see
  • 2 changed file(s) yielded no anchor (packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json) — pages documenting those are invisible to this run
  • 2 anchor(s) matched too much of the corpus to be a work list: VALIDATION_ERROR (literal, 38 pages), master_detail (literal, 49 pages)
  • 5 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 176 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 02520ab4808e46fa708ca257b11981499079d3ae → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 1dca7cd3c8a601a03e872fa9ba2078e48a1b55e5 — the merge of head 760716bcbbcc3e4a64ae9ecae9b710d76743b289 into base 02520ab4808e46fa708ca257b11981499079d3ae, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 1dca7cd3c8a601a03e872fa9ba2078e48a1b55e5 && git checkout 1dca7cd3c8a601a03e872fa9ba2078e48a1b55e5
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 02520ab4808e46fa708ca257b11981499079d3ae 760716bcbbcc3e4a64ae9ecae9b710d76743b289 && git checkout -B drift-repro 02520ab4808e46fa708ca257b11981499079d3ae && git merge --no-ff 760716bcbbcc3e4a64ae9ecae9b710d76743b289

node scripts/docs-audit/affected-docs.mjs --json 02520ab4808e46fa708ca257b11981499079d3ae

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 02520ab4808e46fa708ca257b11981499079d3ae → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

维护者速读

  • 这个 PR 做的事:知识检索可以限定范围,只在指定的几条记录里找,或者只在一份上级记录(比如一份制度)下面的条款里找。按您 Q3 选的 B 实现。
  • 复核结论:设计和代码与 ADR 补充说明一致,范围只会缩小结果,不会放宽权限。但现在还不能合并,退回补两件事。
  • 第一件:一项安全清点测试变红。新代码用了"查某个字段指向哪个对象"的公共函数,清点表要求每个使用方都登记。复核判断:这里只读条款自己的字段定义,不读上级记录,登记为"不提供目标对象内容的读取"是对的。登记要改一个认领范围之外的测试文件,dev 的改动被自动模式拦下,已请您在卡片线程里定。
  • 第二件:按记录返回的那个 PR(feat(service-knowledge): search answers records, not passages — granularity, groupBy and a freshness check #37335)已经合并,这个 PR 与主干有一行文字冲突,需要合入主干。复核试合过:两处过滤都保留,两个包的测试全过。
  • 需要您做的:在卡片线程里同意把那一行登记加进安全清点表(或指定别的做法)。其余由座位跟进,新提交出来后再做一轮差量复核。

席位核对

REWORK — the member, its reader and the suite cases match the dated K8 note and every acceptance scene is pinned, but the head has one red check caused by the diff and conflicts with main. Two must-fix items, three should-fix, four nits; a delta round follows the new head.

Head-sha: 857a2e2024c14709e2da98fc910ef56168ca139f

Read whole at this head against 13ffe1c04565150c174e88806c2fc32d70a04cc8 (the merge base): 15 files, +1160 / -22.

形态

门禁 check-runs (at 857a2e20, read 2026-11-25 about 19:45Z)

  • 47 success, 10 skipped, 9 in progress, 1 failed. Lint & Repo Gates: success. Type Check · workspace: not measured (running). All-green: no.
  • Failed: Test Core (9/10). packages/core/src/security/second-object-read-exposure.pin.test.ts line 580 does not know a new caller of referenceTargetOf, packages/services/service-knowledge/src/knowledge-search-scope.ts. Reproduced locally at this head; caused by this diff, not a flake.
  • Local at 857a2e20: service-knowledge vitest 323/323 (12 files), knowledge-memory 44/44 (2 files), as the report says.

逐项核对与消融 (21 single-change ablations at this head in a scratch worktree, each restored; worktree removed)

  1. Scene 1 (20 records, two in scope, topK: 5, a full page) — the service case and the suite case on knowledge-memory. Adapter filter removed: 7 suite cases red.
  2. Scene 2 (an adapter that ignores the member) — after-answer check removed: 7 red in service-knowledge, 1 in knowledge-memory. Log-once guard removed: 4 red.
  3. Scene 3 (an object no source reaches) — an unreached source left searched: 4 red. The answer type is the hit list alone; no count is in it.
  4. Scene 4 (an unreadable scoped record) — pinned by its own case; the re-read is untouched by the diff.
  5. Scene 5 (bounds) — entries bound raised: 3 red; ids bound raised: 3 red; code and status removed: 13 red. The cases assert code, status and the message.
  6. Scene 6 (the suite) — runs on knowledge-memory and both stubs; no other in-tree adapter runs it at this head.
  7. Carry-over 1 (metadata on hits) — knowledge-memory hits without metadata: 2 red. Text placement: see ruling (b).
  8. Carry-over 2 (string compare) — strict compare in the service: 2 red; in the adapter: 2 red.
  9. Carry-over 3 (empty scope) — three ablations (service list, service entry, adapter list): 1 red each.
  10. Carry-over 4 (bounds on the member's TSDoc, coded refusal) — present on both TSDocs; pinned as scene 5.
  11. Carry-over 5 (the opaque filter finding) — in the body's Acceptance notes, item 5.
  12. Readings of the note — first-field-wins: 2 red; user as a link: 1 red; withheld field kept: 1 red; fail-open on a missing value: 3 red; unknown entry key ignored: 1 red; file / http source reached: 1 red.
  13. Not pinned: the copy of the terms handed to the adapter (no case red when the live terms are handed). The self-target guard in parentLinksOf has no effect on the answer (no case red; the own-object branch returns first).

dev 所提三问的裁定

  • (a) packages/spec/api-surface/contracts.json and packages/spec/export-origins/contracts.json: accepted deviation. One line each, the regen of the claimed AdapterScopeTerm export, required by check:generated.
  • (b) KnowledgeHit.metadata TSDoc: the requirement on AdapterSearchOptions.scope plus the two pins meets carry-over 1 in substance. The hit-side sentence is still owed as should-fix 4, because an adapter that never reads scope reads the hit type. feat(service-knowledge): search answers records, not passages — granularity, groupBy and a freshness check #37335 has landed, so the file is free: the seat extends the surface by that one TSDoc line in packages/spec/src/ai/knowledge-document.zod.ts, in the merge-main commit. No generated artifact copies that comment.
  • (c) scripts/adr-anchors: no gate requires an entry. The registry is opt-in, pnpm check:adr-anchors passes without one, no knowledge file has one, and the touched files cite ADR-0161 in place. Not owed here and no follow-up owed.

安全清点表的归类 (asked by the coordinator)

  • The correct kind for knowledge-search-scope.ts is not-a-served-read. The file resolves a target name from the indexed object's own registered definition, compares it with the name the caller supplied, and reads no record and no definition of the target. The filter it produces is on the indexed object's own stored field, which source admission already holds to be queryable by the caller. decided, executes and open each describe a read of the target and do not fit.
  • The row sits in packages/core/src/security/second-object-read-exposure.pin.test.ts, outside the claim. The dev's edit was refused by auto mode and the question is with the maintainer in the card thread; the seat does not apply it in the dev's place.

逐句核的散文面

修复清单

  1. must-fix — classify knowledge-search-scope.ts in the pin file as not-a-served-read, once the maintainer or the seat extends the surface to that file.
  2. must-fix — merge main. One conflict, in search(): keep both source filters. Probe on the trial merge: 344/344 and 47/47.
  3. should-fix — one case pinning that a parent scope asks the engine nothing about the parent object and that an adapter changing the terms it was handed does not change the service's check. The pin-file row can then cite it.
  4. should-fix — the KnowledgeHit.metadata sentence of ruling (b).
  5. should-fix — on AdapterSearchOptions.scope, "never taken from a caller's input as given" is true of the term shape and reads as if the ids were cleaned. Say that the ids are the caller's strings as given and are bound as parameters, and that field is a name from the source's metadataFields.
  6. nit — no bound on the length of one id; the tool door (search_knowledge: the one definition gains scope, granularity and groupBy, for the MCP door and the in-app agent alike #37311) is the place.
  7. nit — the self-target guard in parentLinksOf is unreachable in effect; keep or drop.
  8. nit — the RAG guide says "The adapter filters before it ranks" for every adapter; the protocol page says "An adapter that reads the member".
  9. nit — the ambiguity log is once per source and object; the note says once per source. Finer, not wider.

接受的偏差

  • Ruling (a). An empty scope is answered empty, not refused. Bounds 10 by 500. An entry with a key besides object and ids is refused. answered stays the adapter's own count.

范围外去向

落地条款

  • Clause-② declared and the path limb hit; the contract record below is FAIL at this head. Not queued. The new head is not prose-only and owes a delta record.

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 857a2e2024c14709e2da98fc910ef56168ca139f
Local-runs: probe — the two package suites, 21 ablations, the failing pin test and a trial merge of main were run in a scratch worktree to confirm what is pinned and what the red check is; nothing was pushed.
Scope: packages/spec/src/contracts/knowledge-adapter.ts, packages/spec/src/contracts/knowledge-service.ts + packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/knowledge-service.ts, packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json
Security-touching: yes
Rule-change-verified: yes

① Derived judgments

  • The member is the one the dated note of 2026-11-25 fixes and no other: AdapterSearchOptions.scope?: AdapterScopeTerm[], a term being { kind: 'record', ids } or { kind: 'metadata', field, ids }. Absent, present and empty read as the note says, and the three filters all apply.
  • KnowledgeSearchOptions.scope is a service option, which K8 names as not a member. implements.scope is a key of the suite's options, not a member.
  • Rule 1 holds: the member lands with its first reader (knowledge-memory) and with suite cases for each term kind and through a real service. Rule 2 holds: optional, and an adapter that ignores it is reported once.
  • The four readings of the note and "what a scope does not reach" are built as written. What the note left open is decided in the body's Acceptance notes and is inside the note's words.

② Semver level

  • Clause-②: yes is right: two optional keys and one exported type widen the published contract. Metadata-protocol: none is right: nothing a metadata author writes changes. patch on the three packages follows the level rule.
  • Additive-safe for existing adapters. knowledge-ragflow and cloud's knowledge-turso do not read the member and keep compiling and answering; both return sourceRecordId and metadata on hits, so the service's check keeps their scoped answers correct and possibly short of topK.
  • The suite's new required implements.scope is a compile-time change for an outside caller; none found, precedent feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256, and the changeset states the fix.

③ Boundary flags

④ Design judgment

packages/spec/src/contracts/knowledge-adapter.ts

  • Holds against the note and against the first reader. Bounds and the hit-metadata requirement are on the member.
  • should-fix 5 — the sentence on where the terms come from needs the id wording.

packages/spec/src/contracts/knowledge-service.ts

  • Holds. Bounds, the empty reading and the coded refusal are stated and true of the code.

packages/services/service-knowledge/src/knowledge-search-scope.ts

  • Agrees with the contract: bounds before anything else, terms per source from the indexed object's definition, hit check fail closed, string compare.
  • must-fix 1 — the census classification. nit 7.

packages/services/service-knowledge/src/knowledge-service.ts

  • Agrees: validation first, admission before the scope, every round checked, counts to logs only.
  • must-fix 2 — merge main. should-fix 3 — the unpinned copy of the terms.

packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts

  • Hold. The suite cases are the ones the note lists; the adapter filters before it ranks and returns metadata.

packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json

  • The regen of the new export; hold.

Findings open at this head: two must-fix, three should-fix, four nits.

Implemented-by: session_01JQwxbZmjM1KubX3ZAoJPPm
Reviewed-by: session_01JQwxbW5anP6GDaVi5LKi2U

VERDICT: FAIL

The record-level search landed on main (#37335). search() keeps both source
filters: the record scope first, then groupBy, each after the scope and
groupBy options are validated.

KnowledgeHit.metadata now says an adapter returns the document's metadata on
each hit, which the service's scope check reads (review ruling (b)).

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
…arent and that an adapter cannot widen the check

- A service case: a parent-scoped search makes no engine call naming the
  parent object, and an adapter that widens the terms it was handed (more
  ids, an extra term) still has every out-of-scope hit dropped; every round
  is handed the service's own terms.
- AdapterSearchOptions.scope: a metadata term's field is a name from the
  source's metadataFields; the ids are the caller's strings as given,
  checked only against the bounds, so an adapter binds them as parameters.
- parentLinksOf: drop the self-target guard; the own-object entry is answered
  before the links are read, so the guard changed no answer.
- The RAG guide says an adapter that reads the scope filters before it ranks,
  and that the service's check may leave an ignoring adapter short of topK.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

维护者速读

  • 这一轮看的是 dev 对上一轮意见的修改:已合入主干,冲突解决正确;上一轮点名的测试、接口说明文字、文档措辞都已补上。
  • 仍不能合并,原因只剩一个硬性项:安全清点表里还缺一行登记。这一行要改认领范围之外的一个测试文件,正在等您在卡片线程里答复。复核意见不变:登记为"不提供目标对象内容的读取"是对的。
  • 本轮新发现一个小缺口:合入主干后,"限定范围"和"按字段分组"两个参数可以同时用。现在代码是对的,但没有测试守住这个组合;把范围过滤在分组时去掉,没有任何测试变红。建议补一个测试用例。
  • 需要您做的:在卡片线程里同意加那一行登记。之后的最后一轮复核只需看两个文件(清点表一行、一个测试用例)。

席位核对

REWORK — the round-1 fixes that were in the dev's reach are closed at this head and the merge of main is resolved correctly. One must-fix stays open because it waits on the maintainer: the census row. One should-fix is new with the merge: the scope combined with groupBy is not pinned.

Head-sha: 3deef5fecc6281d094c702b2656925e92814d0c6

Delta review: two commits on 857a2e2024c14709e2da98fc910ef56168ca139f, no force push. 67f11a57 merges main at a182fbe37765ab486f3aa5e372ffa9d6af1f6758; 3deef5fe adds one test case. The PR's own delta, read as the difference of the two three-dot diffs: one test case added, one guard removed, three prose edits. The rest of the PR stands as read in round 1 (PR comment 7172822171).

形态

  • Open, draft, base main, first line Fixes #37308. Declarations unchanged: Clause-②: yes · Metadata-protocol: none, three packages patch. mergeable_state is blocked, no longer dirty.
  • Not governed surface: check-governed-merges.mjs --pr 37342 reads 0 of 16 paths on the register, 1236 changed lines.
  • One path is new in the file list: packages/spec/src/ai/knowledge-document.zod.ts, inside the amended claim surface (the one TSDoc sentence of ruling (b)).

门禁 check-runs (at 3deef5fe, read 2026-11-25 about 20:10Z)

  • 16 success, 9 skipped, 22 in progress, 0 failed so far. Lint & Repo Gates: not measured (running). Type Check · workspace: not measured (running). All-green: not measured.
  • Test Core (9/10) is still running. It is expected red at this head for the round-1 reason: the census row is not in the tree.
  • Local at 3deef5fe: service-knowledge vitest 345/345 (12 files), knowledge-memory 47/47 (2 files).

逐项核对与消融 (4 single-change ablations at this head in a scratch worktree, each restored; worktree removed)

  1. must-fix 1, the census row — open. Not in the tree; waits on the maintainer's answer in the card thread.
  2. must-fix 2, merge main — closed. In search() the scope is validated first, then sourcesInScope and sourcesGroupableBy both filter the admitted sources. Both rounds of feat(service-knowledge): search answers records, not passages — granularity, groupBy and a freshness check #37335's record-level path go through searchRound, so every round is handed the terms and checked. The freshness check reads records and calls no adapter.
  3. should-fix 3, the pin — closed. The new case reads every engine call through a proxy, as the system identity and as a person. Live terms handed to the adapter: that case red. A read of the parent's definition added: that case red.
  4. should-fix 4, KnowledgeHit.metadata — closed. The sentence is true of the code. No generated artifact moved with it.
  5. should-fix 5, the scope TSDoc — closed. It now says the ids are the caller's strings as given, bound as parameters, and that field is a name from the source's metadataFields.
  6. nit 7 (the self-target guard) dropped; nit 8 (the RAG guide sentence) fixed. Nits 6 and 9 unchanged, accepted.
  7. New — the scope combined with groupBy. The scope filter skipped whenever groupBy is passed: no case red. The grouping filter made to rebuild its entries, which drops the terms: no case red. A probe case shows the code right at this head for groupBy and for granularity: 'record'.

逐句核的散文面 (delta sentences)

  • content/docs/ai/knowledge-rag.mdx: "An adapter that reads the scope filters before it ranks" and "an adapter that ignores it may answer fewer than topK" — true.
  • PR body: three places are stale at this head. The local-runs block names 857a2e20 with 323 and 44; Acceptance note 1 says the KnowledgeHit.metadata TSDoc is not touched; the merge note gives the filter order the other way round. A body edit, no head move.

修复清单

  1. must-fix — add exactly one CALLERS row, kind not-a-served-read, for packages/services/service-knowledge/src/knowledge-search-scope.ts in packages/core/src/security/second-object-read-exposure.pin.test.ts, and nothing else in that file. The row can cite the new case of knowledge-service.test.ts as its behaviour pin.
  2. should-fix — one case in knowledge-service.test.ts: a scope with groupBy, over an adapter that ignores the member; the adapter is handed the terms and no out-of-scope record answers.
  3. should-fix — refresh the three stale places of the PR body.
  4. nit — sourcesGroupableBy is typed without scope and runs after sourcesInScope, so the terms pass through it as an undeclared property. Either order answers the same today; item 2 is what holds it.

接受的偏差 (unchanged from round 1)

  • The two generated spec artifacts. An empty scope answered empty. Bounds 10 by 500. An entry with another key refused. answered the adapter's own count. No scripts/adr-anchors entry.

范围外去向 (unchanged)

落地条款

  • The contract record below is FAIL at this head, for the census row alone among must-fix items. Not queued. The last round is a delta of two files: the pin file's one row and the test case of item 2.

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 3deef5fecc6281d094c702b2656925e92814d0c6
Local-runs: probe — the two package suites, 4 ablations and one probe case were run in a scratch worktree to confirm the round-1 fixes and the merge resolution; nothing was pushed.
Scope: packages/spec/src/contracts/knowledge-adapter.ts, packages/spec/src/contracts/knowledge-service.ts, packages/spec/src/ai/knowledge-document.zod.ts + packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/knowledge-service.ts, packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json
Security-touching: yes
Rule-change-verified: yes

① Derived judgments

② Semver level

  • Unchanged: Clause-②: yes, Metadata-protocol: none, patch on the three packages. A TSDoc sentence in a .zod.ts file changes no schema and no generated artifact.

③ Boundary flags

④ Design judgment

packages/spec/src/contracts/knowledge-adapter.ts

  • Round-1 should-fix closed. Holds.

packages/spec/src/ai/knowledge-document.zod.ts

  • The one sentence on metadata; holds against the service's check and against knowledge-memory.

packages/spec/src/contracts/knowledge-service.ts

packages/services/service-knowledge/src/knowledge-search-scope.ts

  • The dropped guard changes no answer. must-fix 1 stays on this file's census row.

packages/services/service-knowledge/src/knowledge-service.ts

  • The merge resolution is right: validation first, both source filters, every round checked.
  • should-fix — the scope with groupBy is not pinned (two ablations, no case red). nit — the terms pass through sourcesGroupableBy untyped.

packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, the two generated artifacts

  • Hold as in round 1; merged cleanly.

Findings open at this head: one must-fix (waits on the maintainer), two should-fix (one of them the PR body), one nit.

Implemented-by: session_01JQwxbZmjM1KubX3ZAoJPPm
Reviewed-by: session_01JQwxbW5anP6GDaVi5LKi2U

VERDICT: FAIL

… record granularity

A scoped search with groupBy, and one with granularity 'record', over an
adapter that ignores the scope: every round is handed the record term, and
no out-of-scope record answers. Red when the scope is skipped under groupBy
or under record granularity, and when the groupBy source filter rebuilds its
entries without the terms.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
…read census

knowledge-search-scope.ts names the object a knowledge source's listed
lookup points at, only to turn a scope entry naming that parent into a
filter on the source's own stored lookup value. It reads no record of the
parent and serves nothing of it: kind not-a-served-read, pinned by the
service case that a parent-scoped search makes no engine call naming the
parent object.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

维护者速读

  • 这一轮是最后一轮复核,只看两处新改动:安全清点表里您同意的那一行登记,以及"限定范围加分组"的测试用例。
  • 两处都核对无误。登记的写法与清点表的分类定义一致;新测试用例能守住上一轮指出的缺口,去掉范围过滤的三种改法都会让它变红。
  • 复核结论:通过,可以合并。合并前还要等这个版本的自动检查全部跑完变绿,目前还有 22 项在运行,其中包括上两轮变红的那一项。本地已验证那项测试通过。
  • 需要您做的:无。检查全绿后由座位排队合并。

席位核对

ACCEPT — the two open items of the round-2 record (PR comment 7173187773) are closed at this head, each verified from the diff and by ablation, and nothing else moved. Landing waits for the checks still running.

Head-sha: d1ca7f0174a2644ca6b94b54d4134bb21122cdc3

Delta review: two commits on 3deef5fecc6281d094c702b2656925e92814d0c6, linear, no merge and no force push; 2 files, +22 / -0. Read whole against that head; the rest of the PR stands as read in rounds 1 and 2 (PR comments 7172822171 and 7173187773).

形态

  • Open, draft, base main, first line Fixes #37308, the only closing keyword in the body. Body and changeset read Clause-②: yes · Metadata-protocol: none; three packages patch. Unchanged.
  • Not governed surface: check-governed-merges.mjs --pr 37342 reads 0 of 17 paths on the register, 1258 changed lines, under the 3000 threshold.
  • The pin file is inside the claim surface as amended, limited to one row, on the maintainer's word on the card at 2026-11-25 22:48Z. @objectstack/core gains a test-file change only; nothing it publishes moves, so no changeset entry is owed for it.
  • mergeable_state is blocked (draft), not dirty. main is 10 commits ahead and touches none of the PR's knowledge, contract or census paths.

门禁 check-runs (at d1ca7f01, read 2026-11-25 about 23:00Z)

  • 17 success, 11 skipped, 22 in progress, 1 cancelled, 0 failed. The cancelled run is a PR-body guards run superseded by a later run of the same name, which is success.
  • Lint & Repo Gates: not measured (its jobs are still running). TypeScript Type Check: source gates success, workspace not measured. Test Core (9/10): not measured (running). All-green: not measured.
  • Local at d1ca7f01: service-knowledge vitest 346/346 (12 files), knowledge-memory 47/47, and second-object-read-exposure.pin.test.ts in the repo project of @objectstack/core 4/4 — the test that was red at the two earlier heads.

逐项核对与消融 (3 single-change ablations at this head in a scratch worktree, each restored; worktree removed)

  1. The census row — d1ca7f01 adds exactly one CALLERS entry, for packages/services/service-knowledge/src/knowledge-search-scope.ts, kind not-a-served-read, and no other line of the file. The reason says what the file does and does not do, in the words the kind asks for: it names the target only to build a filter on the source's own stored value, reads no record of the parent and serves nothing of it. It cites the service case and the unit file as its pins; both exist.
  2. The combined case — ca5a0c11 adds one case: a scope with groupBy, and with granularity: 'record', over an adapter that ignores the member. It asserts that every round is handed the terms and that no out-of-scope record answers. The grouping filter made to rebuild its entries: that case red. The scope filter skipped under groupBy: red. Skipped under record granularity: red.
  3. The PR body — the three stale places are fixed: the local-runs block is pinned to ca5a0c11 with 346 and 47; Acceptance note 1 names the KnowledgeHit.metadata sentence; the merge note gives the filter order as the code has it. The body also says its 118 derived gates do not reach the census pin and that the row closes it.

接受的偏差 (unchanged)

  • The two generated spec artifacts. An empty scope answered empty. Bounds 10 by 500. An entry with another key refused. answered the adapter's own count. No scripts/adr-anchors entry. No bound on the length of one id (the tool door, search_knowledge: the one definition gains scope, granularity and groupBy, for the MCP door and the in-app agent alike #37311). The ambiguity log once per source and object. sourcesGroupableBy typed without the terms, now held by the combined case.
  • The body's local-runs block is pinned to ca5a0c11, one commit under the head; the commit above it changes one test file of another package, run here at the head.

范围外去向 (unchanged)

落地条款

  • Clause-② declared and the path limb hit: the contract record below is PASS at this head. Queue only when every check at the landing head is green or an expected skip, Test Core (9/10) among them; a head that moves past prose owes a fresh record.

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: d1ca7f0174a2644ca6b94b54d4134bb21122cdc3
Local-runs: probe — the two package suites, the census pin test and 3 ablations were run in a scratch worktree to confirm the two round-2 items are closed; nothing was pushed.
Scope: packages/spec/src/contracts/knowledge-adapter.ts, packages/spec/src/contracts/knowledge-service.ts, packages/spec/src/ai/knowledge-document.zod.ts + packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/knowledge-service.ts, packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, packages/core/src/security/second-object-read-exposure.pin.test.ts, packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json
Security-touching: yes
Rule-change-verified: yes

① Derived judgments

  • Rounds 1 and 2 stand: the member is AdapterSearchOptions.scope?: AdapterScopeTerm[] as the dated K8 note of 2026-11-25 fixes it, with its first reader and its suite cases, and no other member. The delta changes no contract file, no source file and no generated artifact: two test files only.
  • The census classification is the one judged in round 1 (record ID: 7172822171) and approved by the maintainer on the card.

② Semver level

  • Unchanged: Clause-②: yes, Metadata-protocol: none, patch on the three packages. The delta publishes nothing.

③ Boundary flags

④ Design judgment

packages/spec/src/contracts/knowledge-adapter.ts, packages/spec/src/contracts/knowledge-service.ts, packages/spec/src/ai/knowledge-document.zod.ts

  • Untouched by the delta; hold as in round 2.

packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/knowledge-service.ts

  • Untouched by the delta. The scope combined with groupBy and with record granularity is now pinned by a case that three ablations turn red.

packages/core/src/security/second-object-read-exposure.pin.test.ts

  • One row, the right kind, a reason true of the code, two pins that exist. Holds.

packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, the two generated artifacts

  • Untouched by the delta; hold.

No must-fix, no should-fix.

Implemented-by: session_01JQwxbZmjM1KubX3ZAoJPPm
Reviewed-by: session_01JQwxbW5anP6GDaVi5LKi2U

VERDICT: PASS

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 25, 2026 23:19
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 25, 2026
knowledge-pgvector and the index fingerprint landed on main (#37337).
searchWithRefusals validates the scope first, filters the admitted sources
by the scope and then by groupBy, and planSearches carries each source's
terms beside its fingerprint: searchRound hands the adapter both `index` and
`scope`. SearchTarget declares the terms, and sourcesGroupableBy keeps the
type of what it filters. The suite, the stubs, knowledge-memory and the
protocol sample declare both the generation keys and `scope`.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
…after merging main

The merge took both sides of the two generated artifacts without a text
merge; regenerated from the merged tree, they list main's
AdapterIndexExpectation and AdapterIndexStatus beside AdapterScopeTerm.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
knowledge-pgvector landed first (#37337), so it implements the scope as
every in-tree adapter that runs the suite does (#37308 item 4). The terms are
a union in the same inner WHERE as the organization filter, before ranking:
a record term on source_record_id, a metadata term on the stored jsonb value
of its field (a string or number equal to an id as text, or a list with such
an element; anything else holds for nothing). Ids and field names go as
bound parameters. A scope with no term that has ids ranks nothing. The live
contract run declares implements.scope, so the suite's record-term,
metadata-term and service-level parent cases run against PostgreSQL.

Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

维护者速读

  • 这一轮是因为排队合并时撞上了文字冲突:开源向量库(pgvector)那个改动先合并了。按卡片第 4 条,主干上每个跑契约测试的存储都要支持"限定范围",所以这个 PR 现在也给 pgvector 加上了。
  • 复核了两件事:与主干的合并没有丢掉对方的任何功能,范围过滤在每一轮检索里都还生效;pgvector 的过滤写在数据库查询里,在排序之前执行,调用方给的 id 和字段名都作为参数传入,没有拼进查询文本。
  • 复核结论:通过,可以重新排队。还要等这个版本的自动检查跑完变绿,目前 21 项在运行。pgvector 的真实数据库测试在本机跑不了,dev 报告 67 项通过,排队时的真实数据库检查会再验证一次。
  • 需要您做的:无。

席位核对

ACCEPT — the merge of main loses nothing of #37337 or #37335 and the scope applies in every round; knowledge-pgvector applies the scope in its search SQL as the member's text asks. Two nits, both in the fail-closed direction. Landing waits for the checks still running.

Head-sha: 760716bcbbcc3e4a64ae9ecae9b710d76743b289

Delta review: three commits on d1ca7f0174a2644ca6b94b54d4134bb21122cdc3, no force push. 93c70347 merges main at 98bda0ac17dbde835e8be577d7d4238e6cf77201; 4552e7c4 regenerates the two contracts artifacts; 760716bc is the pgvector reader, 6 files, +38 / -4. The PR against its merge base: 19 files, +1272 / -28. The rest stands as read in rounds 1 to 3 (PR comments 7172822171, 7173187773, 7176979005).

形态

  • Open, not draft, base main, first line Fixes #37308, the only closing keyword in the body. Body and changeset read Clause-②: yes · Metadata-protocol: none; @objectstack/knowledge-pgvector joins the changeset at patch beside the three others.
  • Not governed surface: check-governed-merges.mjs --pr 37342 reads 0 of 19 paths on the register, 1300 changed lines, under the 3000 threshold.
  • packages/plugins/knowledge-pgvector/** is inside the claim as widened after feat(knowledge): knowledge-pgvector, an open vector store on PostgreSQL, and the index fingerprint (#37100) #37337 landed: the scope filter in search(), implements.scope, and nothing else in that package. Fixes still holds: card item 4 is now met for every in-tree adapter on main that runs the suite.
  • mergeable_state is blocked, not dirty; main is 2 commits ahead.

门禁 check-runs (at 760716bc, read 2026-11-26)

  • 19 success, 11 skipped, 21 in progress, 0 failed. Lint & Repo Gates: not measured (its jobs are still running). Type Check · source gates success, workspace not measured. Test Core, all ten shards: not measured. All-green: not measured.
  • Temporal Conformance (live PG + MySQL) is an expected skip on the PR; the queue run carries it.
  • Local at 760716bc: service-knowledge vitest 365/365 (13 files), knowledge-memory 56/56, the repo project of @objectstack/core 110/110 (8 files). knowledge-pgvector: 10 passed, 57 skipped — its live cases need PostgreSQL with pgvector, absent here. Live coverage: not measured by this seat; the dev reports 67/67 against a local PostgreSQL 16 with pgvector and 7 red with the filter removed.

逐项核对与消融 (4 single-change ablations at this head in a scratch worktree, each restored; worktree removed)

  1. Merge, nothing lost — every line the PR removes against main is one of its own edits. searchWithRefusals keeps feat(knowledge): knowledge-pgvector, an open vector store on PostgreSQL, and the index fingerprint (#37100) #37337's refusal report whole (the coded refusal per source, the whole refusal, the refill-refusal rule) and feat(service-knowledge): search answers records, not passages — granularity, groupBy and a freshness check #37335's record path whole (answerByRecord, the freshness check).
  2. Merge, the scope in every round — the scope is validated first; admitted sources are filtered by the scope, then by groupBy (now generic, so the terms are typed through it), then planned. SearchTarget carries the terms; searchRound hands the fingerprint and a copy of the terms, and checks every hit. The plan made to drop the terms: 13 red. The refill round asked without them: 4 red. The scope skipped under groupBy: 1 red. The after-answer check removed: 9 red.
  3. pgvector, binding — ids go as one bound text array per term and the field name as one bound text parameter; no caller value and no field name is written into the statement text.
  4. pgvector, before ranking — the terms are one parenthesised union in the inner WHERE, beside the source, generation and organization conditions, under the ORDER BY and LIMIT.
  5. pgvector, the same reading as the service's check — probed on a local PostgreSQL 16 (plain jsonb, no vector): a string and a number match their id as text; a list matches when a string or number element does; an object, null, a boolean, a nested list, an empty list, a missing key and a row with no metadata match nothing; a record term on a row with no record id matches nothing.
  6. pgvector, empty — a scope with no term that has ids answers nothing before any query; a term with no ids adds no condition and the others still apply.
  7. The generated artifacts — against main each still gains one line, AdapterScopeTerm; the two extra lines of 4552e7c4 are feat(knowledge): knowledge-pgvector, an open vector store on PostgreSQL, and the index fingerprint (#37100) #37337's exports arriving through the merge.

逐句核的散文面 (delta sentences)

  • Changeset: "@objectstack/knowledge-pgvector applies it in the same SQL WHERE as the organization filter, ids and field names as bound parameters" — true.
  • content/docs/protocol/knowledge.mdx: the pgvector search bullet and the adapter table row now name the record scope — true.
  • PR body: the local-runs block is pinned to 760716bc; the pgvector paragraph and the merge note match the code.

修复清单

  1. nit — a metadata value stored as a number of 1e21 or more reads as digits in SQL and in exponent form in the service's check, so such a value is in no scope on this adapter. No record id is such a number; the direction is fewer hits, never more.
  2. nit — an id holding a NUL byte is expected to make the statement fail on PostgreSQL, so that source answers nothing for that search and the failure is logged. Not run here. The tool door (search_knowledge: the one definition gains scope, granularity and groupBy, for the MCP door and the in-app agent alike #37311) can refuse such an id with the length bound already noted.

接受的偏差 (unchanged, plus one)

  • As in round 3. New: the live pgvector cases were not run by this seat; the dev's run and the queue's live run stand for them.

范围外去向 (unchanged)

落地条款

  • Clause-② declared and the path limb hit: the contract record below is PASS at this head. Queue only when every check at the landing head is green or an expected skip; the queue's live PostgreSQL run is the proof of the pgvector cases. A head that moves past prose owes a fresh record.

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 760716bcbbcc3e4a64ae9ecae9b710d76743b289
Local-runs: probe — three package suites, the census project, 4 ablations and one jsonb predicate probe on a local PostgreSQL were run to confirm the merge resolution and the pgvector reading; nothing was pushed.
Scope: packages/spec/src/contracts/knowledge-adapter.ts, packages/spec/src/contracts/knowledge-service.ts, packages/spec/src/ai/knowledge-document.zod.ts + packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/knowledge-service.ts, packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts, packages/core/src/security/second-object-read-exposure.pin.test.ts, packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json
Security-touching: yes
Rule-change-verified: yes

① Derived judgments

  • Rounds 1 to 3 stand: the member is AdapterSearchOptions.scope?: AdapterScopeTerm[] as the dated K8 note of 2026-11-25 fixes it, and no other member. The delta changes no contract text; the three spec source files are as read in round 2, merged cleanly beside feat(knowledge): knowledge-pgvector, an open vector store on PostgreSQL, and the index fingerprint (#37100) #37337's members.
  • The delta adds a second reader, knowledge-pgvector, which K8 rule 1 names as a runner of the suite and card item 4 requires once it is on main. It declares implements.scope and so runs every scope case of the suite on a live database.

② Semver level

  • Unchanged: Clause-②: yes, Metadata-protocol: none. @objectstack/knowledge-pgvector at patch is right: it reads an optional member and adds no option of its own.

③ Boundary flags

④ Design judgment

packages/spec/src/contracts/knowledge-adapter.ts, packages/spec/src/contracts/knowledge-service.ts, packages/spec/src/ai/knowledge-document.zod.ts

  • Hold as in round 2. The pgvector reader does what the member's text tells an adapter: filter before ranking, bind the ids, return the document's metadata.

packages/services/service-knowledge/src/knowledge-service.ts

  • The merge resolution agrees with the contract: bounds first, admission before the scope, the terms carried through the plan into every round, every hit checked, counts to logs only. Four ablations each turn cases red.

packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts

  • Agrees with the term type: a record term on the stored record id, a metadata term on the stored value or any element of a stored list, strings and numbers compared as text, anything else and no value matching nothing. Two edge readings are recorded in the seat section; both answer fewer hits, never more, and the service's check after the answer is unchanged.

packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, packages/core/src/security/second-object-read-exposure.pin.test.ts, the two generated artifacts

  • Hold as in round 3; merged cleanly.

No must-fix, no should-fix.

Implemented-by: session_01JQwxbZmjM1KubX3ZAoJPPm
Reviewed-by: session_01JQwxbW5anP6GDaVi5LKi2U

VERDICT: PASS

Merged via the queue into main with commit 98b17fe Nov 26, 2026
74 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-3zr6fx branch November 26, 2026 01:10
os-warren pushed a commit that referenced this pull request Nov 26, 2026
Brings #37342 (record scope). Conflict in content/docs/protocol/knowledge.mdx's
adapter table: both rows kept.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbaMuehXzctoWq7iRsV
os-warren pushed a commit that referenced this pull request Nov 26, 2026
…ng (ADR-0161 K8 item 17)

Mirrors knowledge-pgvector's scope from #37342: the terms are ORed inside
the organization-filtered WHERE, a record term on source_record_id, a
metadata term on a stored string or number equal to an id as text or a list
with such an element. Ids go as one bound JSON array per term; a field name
is a bound value compared with the stored keys, never a JSON path. A scope
with no term that has ids answers [] before any query. The contract suite
runs with implements.scope: true.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbaMuehXzctoWq7iRsV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:ai size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking

2 participants